﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;


namespace Battleships_2
{
    class ShipCannon
    {
        public Vector2 cannonPosition = new Vector2(0, 0);
        public Texture2D cannonTexture;
        public Vector2 cannonCenter;
        public float cannonAngle = 0f;

        public float CannonAim()
        {
            MouseState currentMouse = Mouse.GetState();
            Vector2 mouseLocation = new Vector2(currentMouse.X, currentMouse.Y);

            Vector2 direction = cannonPosition - mouseLocation;

            return (float)(Math.Atan2(direction.X, direction.Y)) * -1;
        }

        public void LoadContent(ContentManager theContentManager, string theAssetName)
        {
            cannonTexture = theContentManager.Load<Texture2D>(theAssetName);
            cannonCenter.X = cannonTexture.Width / 2;
            cannonCenter.Y = 30;
        }

        public void Draw(SpriteBatch theSpriteBatch)
        {
            theSpriteBatch.Draw(cannonTexture, cannonPosition, null, Color.Wheat, cannonAngle, cannonCenter, 1.0f, SpriteEffects.None, 0f);
        }
    }
}
